<?php
namespace app\admin\controller;
use think\Db;
class Exam extends Base
{
    public function index()
    {

        return $this->fetch();
    }
	
	//获取科目列表
	//参数：无
	//返回值：科目列表数组
	public function getSubjectList($args = 1)
	{
		$subjects=Db::table('subject')->select();
		$this->assign('subjects',$subjects);
		return $this->fetch();
		//$data = array(false,'subject',$args);
		//$sql = $this->pdosql->makeSelect($data);
		//return $this->db->fetchAll($sql,'subjectid','subjectsetting');
		//$sql='SELECT * FROM x2_subject WHERE 1 LIMIT 512';
	}
	//根据科目ID查询所属章节
	public function section()
	{
		//SELECT * FROM x2_sections WHERE sectionsubjectid = :sectionsubjectid ORDER BY sectionid ASC LIMIT 0,10
		$subjectid = input('subjectid');
		//var_dump($subjectid);
		//exit;
		$subjects=Db::table('subject')->select();
		$sections=Db::table('sections')->where(array('sectionsubjectid'=>$subjectid))->select();
		$this->assign('subjectid',$subjectid);
		$this->assign('subjects',$subjects);
		$this->assign('sections',$sections);
		return $this->fetch();
	}
	//根据章节ID查询知识点
	public function point()
	{
		$sectionid = input('sectionid');
		$subjects=Db::table('subject')->select();
		$knows=Db::table('knows')->where(array('knowssectionid'=>$sectionid))->select();
		$this->assign('sectionid',$sectionid);
		$this->assign('subjects',$subjects);
		$this->assign('knows',$knows);
		//var_dump($knows);
		//exit;
		return $this->fetch();
		
	}
	//查询题目
	public function questype()
	{
		$questypes = Db::table('questype')->select();
		//var_dump($questypes);
		//exit;
		$this->assign('questypes',$questypes);
		return $this->fetch();
	}
	//添加科目
	public function addsubject()
	{
		if(input(''))
		{
		$name=input('name');
		$subjectsetting=input('subjectsetting/a');
		$ms=array();
		foreach($subjectsetting as $key=>$val)
		{
			$ms[$val]=1;
		}
		//var_dump($ms);
		//exit;
		//var_dump($subjectsetting);
		//exit;
		$data=Db::table('subject')->where(array('subject'=>$name))->find();
		if($data)
		{
			$this->success('名称已存在', 'Exam/addsubject');
		}
		$data=array(
		'subject'=>$name,
		'subjectsetting'=>serialize($subjectsetting)
		);
		$ms=Db::table('subject')->insert($data);
		if($ms)
		{
			$this->success('添加成功', 'Exam/getSubjectList');
		}
		else
		{
			$this->success('添加失败', 'Exam/getSubjectList');
		}
		}
		else
		{
		$subjects=Db::table('subject')->select();
		$questypes = Db::table('questype')->select();
        $this->assign('questypes',$questypes);
        $this->assign('subjects',$subjects);
        return $this->fetch();		
		}
	}
	public function upsubject()
	{
		$id=input('id');
		$ms=Db::table('subject')->where(array('subjectid'=>$id))->find();
		//var_dump(unserialize($ms['subjectsetting']));
		//exit;
		$mk=unserialize($ms['subjectsetting']);
		var_dump($mk);
		exit;
		$ms['subjectsetting']=implode("/",$mk['questypes']);
		var_dump($ms['subjectsetting']);
		exit;
		$questypes = Db::table('questype')->select();
		$this->assign('questypes',$questypes);
		$this->assign('ms',$ms);
		return $this->fetch();
	}
	
}
